using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Navigation;
using Lib.Helper;
using Lib.Mail;
using MSIACCSL2.Command;
using MSIACCSL2.InventoryServices;
using MSIACCSL2.MutasiPalletServices;
using MSIACCSL2.PalletServices;
using MSIACCSL2.Views.MutasiPallet;
using MSIACCSL2.WarehouseServices;
using WcfService1.DTO;
using GetListByCriteriaCompletedEventArgs = MSIACCSL2.MutasiPalletServices.GetListByCriteriaCompletedEventArgs;
using GetListCompletedEventArgs = MSIACCSL2.MutasiPalletServices.GetListCompletedEventArgs;
using SaveCompletedEventArgs = MSIACCSL2.MutasiPalletServices.SaveCompletedEventArgs;

namespace MSIACCSL2.ViewModels
{
    public class MutasiPalletViewModel : ViewModelBase
    {
        #region Delegates

        public delegate void Completed(Object param);

        #endregion

        private static Search frmSearch;
        private static string OrderType;
        private static string PropertySort;
        public static Mode mode;
        private static FrmAdd frmAdd;
        public static Completed OnSearchCompleted;
        private static NavigationService _NavigationService;
        private readonly WarehouseServicesClient WarehouseClient;


        private readonly ValidationHandler validationHandler;
        private int CurrentPage;
        private PalletServicesClient FromPalletClient;
        private ObservableCollection<int> Pages;
        private PalletServicesClient ToPalletClient;
        private ObservableCollection<PalletDTO> _FromPallets;
        private bool _IsBusy;
        private MutasiPalletDTO _MutasiPallet;
        private PagedCollectionView _MutasiPallets;
        private ObservableCollection<PalletDTO> _ToPallets;
        private ObservableCollection<WarehouseDTO> _Warehouses;
        private List<string> _errors;
        private Visibility _messageVisibility;
        private PagedCollectionView _pageSources;
        private MutasiPalletServicesClient client;


        public MutasiPalletViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                client = new MutasiPalletServicesClient();
                WarehouseClient = new WarehouseServicesClient();
                OnPageChanged = new DelegateCommand(PageIndexChanged, CanPageIndexChanged);
                Save = new DelegateCommand(SaveMutasiPallet, CanSave);
                New = new DelegateCommand(NewMutasiPallet, CanNew);
                Unload = new DelegateCommand(Release, CanUnload);
                SearchCommand = new DelegateCommand(SearchMutasiPallet, CanSearch);
                SearchResultCommand = new DelegateCommand(SearchResult, CanSearchResult);
                CancelCommand = new DelegateCommand(Cancel, CanCancelCommand);
                GetPalletCommand = new DelegateCommand(GetPallet, CanGetPAlletCommand);
                validationHandler = new ValidationHandler();
                MessageVisibility = Visibility.Collapsed;

                if (mode == Mode.Edit)
                {
                    //GetFromPalletList();
                    //GetToPalletList();
                    GetWarehouseList();

                    MutasiPallet = (MutasiPalletDTO) Navigation.Args;
                    if (MutasiPallet.MutasiPalletDetails == null)
                        MutasiPallet.MutasiPalletDetails = new ObservableCollection<MutasiPalletDetailDTO>();
                    if (MutasiPallet.MutasiPalletDetails.Count == 0)
                        MutasiPallet.MutasiPalletDetails.Add(new MutasiPalletDetailDTO());
                }
                else if (mode == Mode.Search)
                {
                    MutasiPallet = new MutasiPalletDTO();
                    //GetFromPalletList();
                    //GetToPalletList();
                    GetWarehouseList();
                }
                else if (mode == Mode.Add)
                {
                    GetLastNoMutasi();
                    //GetFromPalletList();
                    //GetToPalletList();
                    GetWarehouseList();

                    MutasiPallet = new MutasiPalletDTO();
                    MutasiPallet.MutasiPalletDetails = new ObservableCollection<MutasiPalletDetailDTO>();
                    var MutasiPalletDetail = new MutasiPalletDetailDTO();
                    MutasiPalletDetail.Inventory = new InventoryDTO();
                    MutasiPallet.MutasiPalletDetails.Add(MutasiPalletDetail);
                }
                else
                {
                    GetList(1, null);
                }
            }
        }

        public PagedCollectionView MutasiPallets
        {
            get { return _MutasiPallets; }

            private set
            {
                if (MutasiPallets == value) return;
                _MutasiPallets = value;
                int i = (CurrentPage*30);
                foreach (object MutasiPallet in MutasiPallets)
                {
                    i += 1;

                    ((MutasiPalletDTO) MutasiPallet).No = i;
                }
                FirePropertyChanged("MutasiPallets");
                MutasiPallets.CollectionChanged += MutasiPallet_CollectionChanged;
            }
        }

        public PagedCollectionView PageSources
        {
            get { return _pageSources; }
            private set
            {
                if (PageSources == value) return;
                _pageSources = value;
                FirePropertyChanged("PageSources");
            }
        }


        public ObservableCollection<PalletDTO> FromPallets
        {
            get { return _FromPallets; }
            private set
            {
                if (FromPallets == value) return;
                _FromPallets = value;
                FirePropertyChanged("FromPallets");
            }
        }


        public ObservableCollection<PalletDTO> ToPallets
        {
            get { return _ToPallets; }
            private set
            {
                if (ToPallets == value) return;
                _ToPallets = value;
                FirePropertyChanged("ToPallets");
            }
        }

        public ObservableCollection<WarehouseDTO> Warehouses
        {
            get { return _Warehouses; }
            private set
            {
                if (Warehouses == value) return;
                _Warehouses = value;
                FirePropertyChanged("Warehouses");
            }
        }


        public bool IsBusy
        {
            get { return _IsBusy; }
            internal set
            {
                _IsBusy = value;
                FirePropertyChanged("IsBusy");
            }
        }


        public long RecordCount { get; set; }

        //Buat binding ke child form waktu mau edit
        public MutasiPalletDTO MutasiPallet
        {
            get { return _MutasiPallet; }
            private set
            {
                if (MutasiPallet == value) return;
                _MutasiPallet = value;
                FirePropertyChanged("MutasiPallet");
            }
        }


        public ICommand OnPageChanged { get; set; }
        public ICommand Save { get; set; }
        public ICommand New { get; set; }
        public ICommand Edit { get; set; }
        public ICommand Unload { get; set; }
        public ICommand SearchCommand { get; set; }
        public ICommand SearchResultCommand { get; set; }
        public ICommand CancelCommand { get; set; }

        public List<string> Errors
        {
            get { return _errors; }
            private set
            {
                if (Errors == value) return;
                _errors = value;
                FirePropertyChanged("Errors");
            }
        }

        public Visibility MessageVisibility
        {
            get { return _messageVisibility; }
            private set
            {
                if (MessageVisibility == value) return;
                _messageVisibility = value;
                FirePropertyChanged("MessageVisibility");
            }
        }

        public string this[string columnName]
        {
            get
            {
                if (validationHandler.BrokenRuleExists(columnName))
                {
                    return validationHandler[columnName];
                }
                return null;
            }
        }

        public ICommand GetPalletCommand { get; set; }

        public void Complete(Object param)
        {
            OnSearchCompleted(param);
        }

        private void MutasiPallet_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (((PagedCollectionView) sender).SortDescriptions.Count > 0)
            {
                if (((PagedCollectionView) sender).SortDescriptions[0].PropertyName.ToLower() == "no") return;

                PropertySort = ((PagedCollectionView) sender).SortDescriptions[0].PropertyName;
                if (string.IsNullOrEmpty(OrderType))
                {
                    OrderType = "ASC";
                }
                else
                {
                    OrderType = OrderType == "ASC" ? OrderType = "DESC" : OrderType = "ASC";
                }
                GetList(1, PropertySort);
            }
        }


        public void SaveMutasiPallet(Object mutasiPallet)
        {
            MutasiPallet = (MutasiPalletDTO) mutasiPallet;
            if (MutasiPallet.MutasiPalletDetails.Count == 1)
            {
                //Bila tidak ada yang dipilih di detail maka details harus dihapus
                if (MutasiPallet.MutasiPalletDetails[0].Inventory == null)
                    MutasiPallet.MutasiPalletDetails.Clear();
            }
            Validate();
            if (Errors.Count > 0) return;
            MutasiPallet.created_by = GlobalVar.User.UserID;
            MutasiPallet.modified_by = GlobalVar.User.UserID;
            client.SaveCompleted += client_SaveCompleted;
            client.SaveAsync(MutasiPallet);
        }

        private void client_SaveCompleted(object sender, SaveCompletedEventArgs e)
        {
            if (e.Error != null) Validate(e.Error.ToString());
            client.SaveCompleted -= client_SaveCompleted;
            if (e.Result)
            {
                MessageBox.Show("Success");
                Navigation.MyNavigation.Navigate(new Uri("/MutasiPallet/Index", UriKind.Relative));
            }
        }


        public void GetList(int? page, string sortProp)
        {
            IsBusy = true;
            client.GetListCompleted += client_GetListCompleted;
            client.GetListAsync(page ?? 1, sortProp, OrderType);
        }

        private void client_GetListCompleted(object sender, GetListCompletedEventArgs e)
        {
            RecordCount = e.recordCount;
            if (PageSources == null) CreatePageNumber();
            client.GetListCompleted -= client_GetListCompleted;
            MutasiPallets = new PagedCollectionView(e.Result);
            IsBusy = false;
            Complete(this);
        }


        private void NewMutasiPallet(Object param)
        {
            mode = Mode.Add;
            //Navigation.MyNavigation = (NavigationService) param;
            Navigation.MyNavigation.Navigate(new Uri("/MutasiPallet/frmAdd", UriKind.Relative));
        }


        private void SearchMutasiPallet(Object param)
        {
            mode = Mode.Search;
            MutasiPallet = new MutasiPalletDTO();
            frmSearch = new Search();
            frmSearch.Show();
        }


        private void SearchResult(Object param)
        {
            var criteria = new Dictionary<string, object>();

            foreach (PropertyInfo prop in MutasiPallet.GetType().GetProperties())
            {
                if (prop.PropertyType == typeof (Decimal))
                {
                    if ((Decimal) prop.GetValue(MutasiPallet, null) == 0) continue;
                }
                if (prop.PropertyType == typeof (Int32))
                {
                    if ((Int32) prop.GetValue(MutasiPallet, null) == 0) continue;
                }
                if (prop.PropertyType == typeof (Int64))
                {
                    if ((Int64) prop.GetValue(MutasiPallet, null) == 0) continue;
                }
                if (prop.PropertyType == typeof (Double))
                {
                    if ((Double) prop.GetValue(MutasiPallet, null) == 0) continue;
                }
                if (prop.PropertyType == typeof (String))
                {
                    if (String.IsNullOrEmpty((String) prop.GetValue(MutasiPallet, null))) continue;
                }
                if (prop.PropertyType == typeof (DateTime))
                {
                    if (prop.GetValue(MutasiPallet, null).ToString().Contains("0001")) continue;
                }
                if (prop.GetValue(MutasiPallet, null) == null) continue;
                if (prop.PropertyType.Name == "No") continue;

                if (prop.PropertyType.Name.ToLower().Contains("dto"))
                {
                    foreach (PropertyInfo propertyInfo in prop.GetValue(MutasiPallet, null).GetType().GetProperties()
                        )
                    {
                        if (propertyInfo.Name.ToLower().Contains("id") || propertyInfo.Name.ToLower().Contains("kode") ||
                            propertyInfo.Name.ToLower().Contains("serial") ||
                            propertyInfo.Name.ToLower().Contains("code"))
                        {
                            criteria.Add(prop.Name, propertyInfo.GetValue(prop.GetValue(MutasiPallet, null), null));
                            break;
                        }
                    }
                }
                else
                {
                    criteria.Add(prop.Name, prop.GetValue(MutasiPallet, null));
                }
            }

            string expression = string.Empty;
            if (frmSearch.rblOr.IsChecked ?? false) expression = "OR";
            else expression = "AND";
            MutasiPalletSearch(criteria, expression);
        }

        private void MutasiPalletSearch(Dictionary<String, Object> criteria, string expression)
        {
            frmSearch.DialogResult = true;
            IsBusy = true;
            Complete(this);
            client.GetListByCriteriaCompleted += client_GetListByCriteriaCompleted;
            client.GetListByCriteriaAsync(criteria, expression, 1);
        }

        private void client_GetListByCriteriaCompleted(object sender, GetListByCriteriaCompletedEventArgs e)
        {
            client.GetListByCriteriaCompleted -= client_GetListByCriteriaCompleted;
            MutasiPallets = new PagedCollectionView(e.Result);
            RecordCount = e.recordCount;
            CreatePageNumber();
            IsBusy = false;
        }


        private void GetFromPalletList()
        {
            FromPalletClient = new PalletServicesClient();
            FromPalletClient.GetAllPalletCompleted +=
                FromPalletClient_GetAllFromPalletCompleted;
            FromPalletClient.GetAllPalletAsync();
        }

        private void FromPalletClient_GetAllFromPalletCompleted(object sender,
                                                                GetAllPalletCompletedEventArgs e)
        {
            FromPalletClient.GetAllPalletCompleted -=
                FromPalletClient_GetAllFromPalletCompleted;
            FromPallets = e.Result;

            if (MutasiPallet != null)
            {
                if (MutasiPallet.FromPallet == null) return;
                MutasiPallet.FromPallet =
                    FromPallets.FirstOrDefault(s => s.KodePallet == MutasiPallet.FromPallet.KodePallet);
            }
        }

        private void GetToPalletList()
        {
            ToPalletClient = new PalletServicesClient();
            ToPalletClient.GetAllPalletCompleted +=
                ToPalletClient_GetAllToPalletCompleted;
            ToPalletClient.GetAllPalletAsync();
        }

        private void ToPalletClient_GetAllToPalletCompleted(object sender,
                                                            GetAllPalletCompletedEventArgs e)
        {
            ToPalletClient.GetAllPalletCompleted -=
                ToPalletClient_GetAllToPalletCompleted;
            ToPallets = e.Result;

            if (MutasiPallet != null)
            {
                if (MutasiPallet.ToPallet == null) return;
                MutasiPallet.ToPallet =
                    ToPallets.FirstOrDefault(s => s.KodePallet == MutasiPallet.ToPallet.KodePallet);
            }
        }

        private void GetWarehouseList()
        {
            WarehouseClient.GetAllWarehouseCompleted += WarehouseClient_GetAllWarehouseCompleted;
            WarehouseClient.GetAllWarehouseAsync();
        }

        private void WarehouseClient_GetAllWarehouseCompleted(object sender, GetAllWarehouseCompletedEventArgs e)
        {
            WarehouseClient.GetAllWarehouseCompleted -= WarehouseClient_GetAllWarehouseCompleted;
            Warehouses = e.Result;
            if (MutasiPallet != null)
            {
                if (MutasiPallet.Warehouse == null) return;
                MutasiPallet.Warehouse =
                    Warehouses.FirstOrDefault(s => s.KodeWarehouse == MutasiPallet.Warehouse.KodeWarehouse);
            }
        }


        private void CreatePageNumber()
        {
            Pages = new ObservableCollection<int>();
            for (int i = 0; i < RecordCount; i++)
            {
                Pages.Add(i);
            }
            PageSources = new PagedCollectionView(Pages);
        }


        private void PageIndexChanged(Object pageIndex)
        {
            //Jika Pertama kali jangan di Getlagi
            MutasiPallet = null;
            if (MutasiPallets != null && CurrentPage != (int) pageIndex)
            {
                CurrentPage = (int) pageIndex;
                if (String.IsNullOrEmpty(PropertySort))
                    GetList((int) pageIndex + 1, null);
                else GetList((int) pageIndex + 1, PropertySort);
            }
        }


        public bool CanPageIndexChanged(Object param)
        {
            return true;
        }


        public bool CanSave(Object param)
        {
            return true;
        }


        public bool CanNew(Object param)
        {
            return true;
        }

        public bool CanEdit(Object param)
        {
            return true;
        }


        public bool CanUnload(Object param)
        {
            return true;
        }


        public bool CanSearch(Object param)
        {
            return true;
        }

        public bool CanSearchResult(Object param)
        {
            return true;
        }

        public bool CanCancelCommand(Object param)
        {
            return true;
        }


        public void Release(Object param)
        {
            param = null;
            MutasiPallet = null;
            OrderType = null;
            PropertySort = null;
            mode = Mode.Idle;
        }


        public void Refresh()
        {
            if (MutasiPallets == null)
                GetList(1, null);
            else
                Complete(this);
        }


        public void Validate(string error = null)
        {
            Errors = new List<string>();
            if (string.IsNullOrEmpty(MutasiPallet.NoMutasi))
                Errors.Add("Nomor Mutasi tidak boleh kosong");
            //validasi detail
            foreach (MutasiPalletDetailDTO mutasiPalletDetail in MutasiPallet.MutasiPalletDetails)
            {
                if (mutasiPalletDetail.Inventory.KodePallet != MutasiPallet.FromPallet.KodePallet)
                    Errors.Add(mutasiPalletDetail.Inventory.SerialNumber + " tidak berada pada pallet " +
                               MutasiPallet.FromPallet.KodePallet);
            }

            if (!string.IsNullOrEmpty(error))
                Errors.Add(error);

            if (Errors.Count > 0)
            {
                MessageVisibility = Visibility.Visible;
            }
            else
            {
                MessageVisibility = Visibility.Collapsed;
            }
        }

        public void Cancel(Object param)
        {
            Navigation.MyNavigation.GoBack();
        }

        private void GetLastNoMutasi()
        {
            client = new MutasiPalletServicesClient();
            client.GetLastNoMutasiCompleted +=
                client_GetLastNoMutasiCompleted;
            client.GetLastNoMutasiAsync();
        }

        private void client_GetLastNoMutasiCompleted(object sender, GetLastNoMutasiCompletedEventArgs e)
        {
            client.GetLastNoMutasiCompleted -=
                client_GetLastNoMutasiCompleted;
            string res = e.Result;
            string formatSO = "0000";
            if (e.Result == string.Empty)
                res = formatSO;
            else
                res = e.Result.Split(new[] {"/"}, StringSplitOptions.RemoveEmptyEntries)[2];
            string soNum = formatSO.Substring(0, formatSO.Length - (int.Parse(res) + 1).ToString().Length) +
                           (int.Parse(res) + 1);

            //MutasiPallet = new MutasiPalletDTO();
            MutasiPallet.NoMutasi = "TP" + GlobalVar.Dep + "/" + DateTime.Now.Year + "/" + soNum;
        }

        public bool CanGetPAlletCommand(Object param)
        {
            return true;
        }

        public void GetPallet(Object param)
        {
            FromPalletClient.GetPalletByWarehouseCompleted += FromPalletClient_GetPalletByWarehouseCompleted;
            FromPalletClient.GetPalletByWarehouseAsync(param as WarehouseDTO);
        }

        private void FromPalletClient_GetPalletByWarehouseCompleted(object sender,
                                                                    GetPalletByWarehouseCompletedEventArgs e)
        {
            FromPalletClient.GetPalletByWarehouseCompleted -= FromPalletClient_GetPalletByWarehouseCompleted;
            FromPallets = e.Result;
            ToPallets = e.Result;
        }

        public void SendEmail(Object param)
        {
            ChooseDestination chooseDestination = new ChooseDestination();
            chooseDestination.Show();
            EventAggregator.RegisterMessage("SendDestination", (x) =>
            {
                IsBusy = true;
                client.SendEmailCompleted += client_SendEmailCompleted;
                client.SendEmailAsync(param as MutasiPalletDTO, (x as WarehouseDTO).EmailFolder);
            });
           
        }

        private void client_SendEmailCompleted(object sender, SendEmailCompletedEventArgs e)
        {
            IsBusy = false;
            client.SendEmailCompleted -= client_SendEmailCompleted;
            if (e.Result) MessageBox.Show("Pengiriman Selesai");
        }
    }


    public class MutasiPalletWrapViewModel : ViewModelBase
    {
        private readonly MutasiPalletServicesClient client;
        private InventoryServiceClient InventoryClient;
        private ObservableCollection<InventoryDTO> _Inventorys;
        private MutasiPalletDetailDTO _MutasiPalletDetail;


        public MutasiPalletWrapViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                EditCommand = new DelegateCommand(Edit, CanEditCommand);
                DeleteCommand = new DelegateCommand(Delete, CanDeleteCommand);
                client = new MutasiPalletServicesClient();
                InventoryClient = new InventoryServiceClient();
                GetInventoryCommand = new DelegateCommand(GetInventory, CanGetInventoryCommand);
                AddDetailCommand = new DelegateCommand(AddMutasiPalletDetail, CanAddDetailCommand);
                DeleteDetailCommand = new DelegateCommand(DeleteMutasiPalletDetail, CanDeleteDetailCommand);
            }
        }

        public MutasiPalletViewModel MutasiPalletViewModel { get; set; }


        public ICommand EditCommand { get; set; }
        public ICommand DeleteCommand { get; set; }
        public ICommand AddDetailCommand { get; set; }
        public ICommand DeleteDetailCommand { get; set; }


        public ObservableCollection<InventoryDTO> Inventorys
        {
            get { return _Inventorys; }
            private set
            {
                if (Inventorys == value) return;
                _Inventorys = value;
                FirePropertyChanged("Inventorys");
            }
        }


        public MutasiPalletDetailDTO MutasiPalletDetail
        {
            get { return _MutasiPalletDetail; }
            private set
            {
                if (MutasiPalletDetail == value) return;
                _MutasiPalletDetail = value;
                FirePropertyChanged("MutasiPalletDetail");
            }
        }

        public ICommand GetInventoryCommand { get; set; }
        public ICommand GetQtyUnitCommand { get; set; }

        public bool CanEditCommand(Object param)
        {
            return true;
        }

        public bool CanDeleteCommand(Object param)
        {
            return true;
        }

        public bool CanAddDetailCommand(Object param)
        {
            return true;
        }

        public bool CanDeleteDetailCommand(Object param)
        {
            return true;
        }


        public void Edit(Object param)
        {
            MutasiPalletViewModel.mode = Mode.Edit;
            Navigation.MyNavigation.Navigate(new Uri("/MutasiPallet/frmAdd", UriKind.Relative));
            Navigation.Args = param;
        }

        public void Delete(Object param)
        {
            client.DeleteCompleted += client_DeleteCompleted;
            client.DeleteAsync((MutasiPalletDTO) param);
        }

        private void client_DeleteCompleted(object sender, AsyncCompletedEventArgs e)
        {
            client.DeleteCompleted -= client_DeleteCompleted;
            MessageBox.Show("Delete Success!");
            MutasiPalletViewModel.mode = Mode.Idle;
            var VM = new MutasiPalletViewModel();
        }


        public void GetInventory(Object param)
        {
            MutasiPalletDetail = (MutasiPalletDetailDTO) param;
            if (MutasiPalletDetail.Inventory == null) MutasiPalletDetail.Inventory = new InventoryDTO();
            string SerialNumber = MutasiPalletDetail.Inventory.SerialNumber;
            InventoryClient = new InventoryServiceClient();
            InventoryClient.GetInventoryCompleted += InventoryClient_GetInventoryCompleted;
            InventoryClient.GetInventoryAsync(SerialNumber);
        }

        private void InventoryClient_GetInventoryCompleted(object sender, GetInventoryCompletedEventArgs e)
        {
            InventoryDTO InventoryTemp = e.Result;
            if (null != InventoryTemp)
            {
                MutasiPalletDetail.Inventory = InventoryTemp;
                MutasiPalletDetail.Inventory.Item = e.Result.Item;
                MutasiPalletDetail.Inventory.SatuanUnit =
                    e.Result.SatuanUnit;
            }
        }

        public void AddMutasiPalletDetail(Object param)
        {
            MutasiPalletDetail = new MutasiPalletDetailDTO();
            MutasiPalletDetail.Inventory = new InventoryDTO();
            MutasiPalletViewModel.MutasiPallet.MutasiPalletDetails.Add(MutasiPalletDetail);
        }

        public void DeleteMutasiPalletDetail(Object param)
        {
            var MutasiPalletDetail = (MutasiPalletDetailDTO) param;
            if (MutasiPalletViewModel.MutasiPallet.MutasiPalletDetails.Count > 1)
            {
                MutasiPalletViewModel.MutasiPallet.MutasiPalletDetails.Remove(MutasiPalletDetail);
                if (MutasiPalletDetail.MutasiPalletDetailId == 0) return;
                client.DeleteDetailCompleted += client_DeleteDetailCompleted;
                client.DeleteDetailAsync(MutasiPalletDetail);
            }
        }

        private void client_DeleteDetailCompleted(object sender, DeleteDetailCompletedEventArgs e)
        {
            if (e.Result == false)
                MessageBox.Show("Delete fail");
        }


        public bool CanGetInventoryCommand(Object param)
        {
            return true;
        }

        public bool CanGetQtyUnit(Object param)
        {
            return true;
        }

        public void GetQtyUnit(Object param)
        {
            MutasiPalletDetail.Inventory.QtyUnit = MutasiPalletDetail.Inventory.QtyPack*
                                                   (MutasiPalletDetail.Inventory.Panjang*
                                                    MutasiPalletDetail.Inventory.Lebar*
                                                    MutasiPalletDetail.Inventory.Tinggi)/
                                                   MutasiPalletDetail.Inventory.SatuanUnit.Pengali;
        }
    }
}

namespace WcfService1.DTO
{
}